var ns;
var app = new Vue({
    el: '#app',
    data: {
      IsShow:false,
      keyword:'',
      NewsType:0,
      messageList:this.dataList,
    },
methods:{
  do_search: function() {
      var that = this;
      //搜索，根据买家昵称
        if(that.keySearch!=''){
          that.get_data();
      }
  },
  get_data:function(){
      var that = this;
      var opt = {
          action: 'getmainchatbybusinessandtype',
          NewsType: that.NewsType,// //消息类型  0:表示全部类型 1：聊天；2：订单：3：系统消息
          keyword: that.keyword,
      };
      ns.post(opt, function(succeed, data, err) {
        //alert(JSON.stringify(data));
          if (succeed) {
            if(data!=null)  {
                that.IsShow=true;
            }
              //给消息列表赋值
              //alert(JSON.stringify(data))
              that.messageList = data;
          } else if (err) {
              api.toast({
                  msg: err,
                  duration: 2000,
                  location: 'bottom'
              });
          }
      })
  },
  open_message_chatdetail: function(id) {
      var that = this;
      ns.openWin('dl_message_chatdetail_frm', '聊天窗口', {
          id: id,
      });
    }
  }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.get_data();
    api.addEventListener({
        name: 'onlogin'
    }, function(ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'shopmsgevent'
    }, function(ret, err){
          app.get_data();
    });
};
//时间戳转换方法    date:时间戳数字
function formatDate(date) {
  var date = new Date(date);
  var YY = date.getFullYear() + '-';
  var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  return YY + MM + DD +" "+hh + mm + ss;
}
